﻿@inject IDataCacheService _dataCacheService
@inject NavigationManager NavigationManager

@if (CatalogItems != null && CatalogItems.Any())
{
    <div class="overflow-x-auto pointer" style="max-height: 500px">
        <MTreeview OpenAll
                   
                   Items="CatalogItems"
                   TItem="ArticleCatalogModel"
                   TKey="string"
                   Activatable
                   ItemKey="u => u.Href"
                   ItemChildren="u => u.Nodes"
                   ItemText="u => u.Text"
                   OnActiveUpdate="OnActiveUpdate">
        </MTreeview>
    </div>
}
else
{
    <div class="text-center">
        暂无目录
    </div>
}




@code {
    [Parameter]
    public string Url { get; set; }
    [Parameter]
    public List<ArticleCatalogModel> CatalogItems { get; set; }

    public void OnActiveUpdate(List<ArticleCatalogModel> model)
    {
        if (model == null || model.Any() == false)
        {
            return;
        }
        NavigationManager.NavigateTo($"{Url}#{model.FirstOrDefault().Href}");
    }
}
